package com.ruoyi.safe.controller.web;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.safe.domain.BizExcludePlan;
import com.ruoyi.safe.domain.BizExcludePlanTask;
import com.ruoyi.safe.domain.dto.BizExcludePlanDTO;
import com.ruoyi.safe.domain.vo.BizExcludePlanDetailVO;
import com.ruoyi.safe.domain.vo.BizExcludePlanVO;
import com.ruoyi.safe.service.IBizExcludePlanService;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 隐患风险排查计划Controller
 *
 * @author buxi
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/exclude/plan")
@AllArgsConstructor
public class BizExcludePlanController extends BaseController {

    private final IBizExcludePlanService bizExcludePlanService;

    /**
     * 查询隐患风险排查计划列表
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(@Validated BizExcludePlanDTO bizExcludePlan) {
        startPage();
        List<BizExcludePlanVO> bizExcludePlanVOS = bizExcludePlanService.selectBizExcludePlanListVO(bizExcludePlan);
        return getDataTable(bizExcludePlanVOS);
    }

    /**
     * 导出隐患风险排查计划列表
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:export')")
    @Log(title = "隐患风险排查计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizExcludePlan bizExcludePlan) {
        List<BizExcludePlan> list = bizExcludePlanService.selectBizExcludePlanList(bizExcludePlan);
        ExcelUtil<BizExcludePlan> util = new ExcelUtil<>(BizExcludePlan.class);
        util.exportExcel(response, list, "隐患风险排查计划数据");
    }

    /**
     * 获取隐患风险排查计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bizExcludePlanService.selectBizExcludePlanById(id));
    }

    /**
     * 新增隐患风险排查计划
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:add')")
    @Log(title = "隐患风险排查计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BizExcludePlan bizExcludePlan) {
        return toAjax(bizExcludePlanService.insertBizExcludePlan(bizExcludePlan));
    }

    /**
     * 修改隐患风险排查计划
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:edit')")
    @Log(title = "隐患风险排查计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizExcludePlan bizExcludePlan) {
        return toAjax(bizExcludePlanService.updateBizExcludePlan(bizExcludePlan));
    }

    /**
     * 修改隐患风险排查计划
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:edit')")
    @Log(title = "隐患风险排查计划", businessType = BusinessType.UPDATE)
    @PutMapping("/editConfig")
    public AjaxResult editConfig(@RequestBody BizExcludePlan bizExcludePlan) {
        return toAjax(bizExcludePlanService.updateBizExcludePlan(bizExcludePlan));
    }

    /**
     * 删除隐患风险排查计划
     */
    @PreAuthorize("@ss.hasPermi('exclude:plan:remove')")
    @Log(title = "隐患风险排查计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizExcludePlanService.deleteBizExcludePlanByIds(ids));
    }

    /**
     * 批量修改隐患风险排查计划
     */
    @Log(title = "隐患风险排查计划", businessType = BusinessType.UPDATE)
    @PutMapping("/update/batch")
    public AjaxResult updateBatch(@RequestBody BizExcludePlan bizExcludePlan) {
        return toAjax(bizExcludePlanService.updateBatchByIds(bizExcludePlan));
    }

    /**
     * 查看排查计划详情
     */
    @GetMapping("/detail/list")
    public TableDataInfo detailList(@Validated BizExcludePlanTask bizExcludePlanTask) {
        List<BizExcludePlanDetailVO> bizExcludePlanVOS = bizExcludePlanService.selectBizExcludePlanDetailListVO(bizExcludePlanTask);
        return getDataTable(bizExcludePlanVOS);
    }

}
